﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.Connection;
using System.Data;
using System.Data.SqlClient;

namespace Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.DAL
{
    class ChiTietHDBan
    {
        private dbConnection Conn;

        public ChiTietHDBan()
        {
            Conn = new dbConnection();
        }

        public DataTable SelectAll()
        {
            return Conn.excuteSelectProcedureQuery("SelectAll_ChiTietHDBan");
        }

        public DataTable SelectID(string MaHDBan)
        {
            SqlParameter[] SqlPara = new SqlParameter[1];
            SqlPara[0] = new SqlParameter("@MaHDBan", SqlDbType.NVarChar, 20);
            SqlPara[0].Value = Convert.ToString(MaHDBan);
            return Conn.excuteSelectProcedureQuery("SelectID_ChiTietHDBan", SqlPara);
        }

        public bool Insert(string MaHDBan, string MaSP, int SoLuong)
        {
            SqlParameter[] sqlPara = new SqlParameter[3];
            sqlPara[0] = new SqlParameter("@MaHDBan", SqlDbType.NVarChar, 20);
            sqlPara[0].Value = Convert.ToString(MaHDBan);
            sqlPara[1] = new SqlParameter("@MaSP", SqlDbType.NVarChar, 20);
            sqlPara[1].Value = Convert.ToString(MaSP);
            sqlPara[2] = new SqlParameter("@SoLuong", SqlDbType.Int);
            sqlPara[2].Value = SoLuong;
            return Conn.executeInsertProcedureQuery("Insert_ChiTietHDBan", sqlPara);
        }

        public bool Update(string MaHDBan, string MaSP, int SoLuong)
        {
            SqlParameter[] SqlPara = new SqlParameter[3];
            SqlPara[0] = new SqlParameter("@MaHDBan",SqlDbType.NVarChar,20);
            SqlPara[0].Value = Convert.ToString(MaHDBan);
            SqlPara[1] = new SqlParameter("@MaSP", SqlDbType.NVarChar, 20);
            SqlPara[1].Value = Convert.ToString(MaSP);
            SqlPara[2] = new SqlParameter("@SoLuong", SqlDbType.Int);
            SqlPara[2].Value = SoLuong;
            return Conn.executeUpdateProcedureQuery("Update_ChiTietHDBan",SqlPara);
        }

        public bool Delete(string MaHDBan)
        { 
            SqlParameter[] SqlPara=new SqlParameter[1];
            SqlPara[0] = new SqlParameter("@MaHDBan",SqlDbType.NVarChar,20);
            SqlPara[0].Value = Convert.ToString(MaHDBan);
            return Conn.executeDeleteProcedureQuery("Delete_ChiTietHDBan",SqlPara);
        }
    }
}
